package com.wk.springframework.common;

import com.wk.springframework.bean.UserService;
import com.wk.springframework.beans.factory.config.BeanPostProcessor;
import com.wk.springframework.common.exception.BeanException;

import static com.wk.springframework.common.constant.CommonConstant.BeanConstant.USER_SERVICE;

public class MyBeanPostProcessor implements BeanPostProcessor {
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeanException {
        if (USER_SERVICE.equals(beanName)) {
            System.out.println("before initialization bean addr " + bean);
            UserService wrapperBean = (UserService) bean;
            System.out.println("before initialization convert bean addr " + wrapperBean);
            wrapperBean.setLocation("广州");
        }
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeanException {
        return null;
    }
}
